package com.mediacloud.app.newsmodule.activity

import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.TextUtils
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chinamcloud.project.shanshipin.activity.TikTokActivity
import com.eventTrack.TXReportManager
import com.mediacloud.app.appfactory.cache.AppConfig
import com.mediacloud.app.assembly.util.*
import com.mediacloud.app.assembly.views.FontResizeView
import com.mediacloud.app.model.CommentCommitPushEvent
import com.mediacloud.app.model.FacadeBean
import com.mediacloud.app.model.interfaces.DataInvokeCallBack
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.model.news.ArticleItemReciver
import com.mediacloud.app.model.news.CatalogItem
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.adaptor.comment.CommentReplyListener
import com.mediacloud.app.newsmodule.adaptor.comment.x.CommentAdapter
import com.mediacloud.app.newsmodule.adaptor.comment.x.MoreReplyItem
import com.mediacloud.app.newsmodule.adaptor.microdynamic.ImgData
import com.mediacloud.app.newsmodule.model.CommentListDataReciver
import com.mediacloud.app.newsmodule.model.NewsCommentItem
import com.mediacloud.app.newsmodule.model.ReplyCommentItem
import com.mediacloud.app.newsmodule.utils.*
import com.mediacloud.app.newsmodule.utils.share.OnShareClickListener
import com.mediacloud.app.newsmodule.utils.share.ShareWrap
import com.mediacloud.app.newsmodule.utils.spider.FollowKit
import com.mediacloud.app.newsmodule.utils.spider.IAttentionCall
import com.mediacloud.app.newsmodule.view.CommentDialog
import com.mediacloud.app.newsmodule.view.FontResizeDialog
import com.mediacloud.app.reslib.config.NewsDetailStyleConfig
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig
import com.mediacloud.app.reslib.enums.XKey
import com.mediacloud.app.user.model.UserInfo
import com.mediacloud.app.util.DisplayUtils
import com.mediacloud.app.util.TimeUtils
import com.scwang.smartrefresh.layout.util.SmartUtil
import com.tencent.mmkv.MMKV
import com.utils.UriTool.isFromH5OpenToReStart
import com.yoake.media.player.utils.XVideoBitRate
import com.yoake.media.player.utils.XVideoItem
import com.zimeiti.details.MediaAuthorDetailActivity
import kotlinx.android.synthetic.main.activity_detail_micro_dynamic.*
import kotlinx.android.synthetic.main.item_author_top.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.wrapContent
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import xyz.doikki.videoplayer.player.VideoView
import kotlin.math.min

/**
 * 微动态  appfactory://com.paytocloud.huaqiyun/type32?articleid=XXX
 */
class MicroDynamicDetailActivity : StyleSetActivity(), FontResizeView.OnFontChangeListener,
    CommentReplyListener {

    var page = 1
    var adapter: CommentAdapter? = null
    var commentListInvoker: CommentListDataInvoker? = null
    var commentListCallBack: CommentListCallBack? = null
    var newsDetailInvoker: NewsDetailInvoker? = null
//    lateinit var commentPop: CommentPopupWindow

    val rect = Rect()
    var mTyReportStartTime: Long = 0
    var mTyReportEndTime: Long = 0
    var isAutoPlay = false
    override fun getLayoutResID(): Int {
        return R.layout.activity_detail_micro_dynamic
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
        try {
            if (AppFactoryGlobalConfig.getAppServerConfigInfo(this)?.getNewsDetailConfig()
                    ?.getLinkedHashSet()?.contains(NewsDetailStyleConfig.COMMENT_BOX)!=true){
                findViewById<View>(R.id.tv_letme_say_gp)?.visibility=View.GONE
            }else{
                findViewById<View>(R.id.tv_letme_say_gp)?.visibility=View.VISIBLE
            }

        }catch (e:Exception){

        }
        //        mCommentListView.setPullRefreshEnable(true);
//        mCommentListView.setXListViewListener(this);
//        mCommentListView.setPullLoadEnable(false);
//        mCommentListView.setOnItemClickListener(this);

        setData()
        getNewsDetail()
        // val fontSize = MMKV.defaultMMKV().getInt(XKey.MICRO_FONT_SIZE, 1)
        // resizeFont(fontSize, AppConfig.zoomSize[fontSize]!!)

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun commentCommitPush(data: CommentCommitPushEvent) {
        collectComment(data.content, data.beReplayUserName, data.beReplayUserId)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun likeCountChange(data: NotifyEvent) {
        val facadeBean = MMKV.mmkvWithID(XKey.FACADE_CACHE_MMKV, MMKV.MULTI_PROCESS_MODE).decodeParcelable(
            XKey.FACADE_CACHE_MMKV + articleItem.getId(),
            FacadeBean::class.java
        )
        if (facadeBean != null) {
            tvLikeCount.text = "${StringUtils.toTenThousand(facadeBean.supportCount)}点赞"
        }
    }

    private fun initView() {
//        commentPop = CommentPopupWindow(this)
//        commentPop.setOnCommentListener { content, beReplayUserName, beReplayUserId -> collectComment(content, "$beReplayUserName", "$beReplayUserId") }
//        commentPop.type = 1
//        commentPop.articleItem = articleItem
//        CommentPopFactroy.articleItem = articleItem
//        commentPop.commentListener = object : CommentPopupWindow.SubmitCommentListener {
//            override fun success() {
//                commentPop.dismiss()
//            }
//
//            override fun failed() {}
//        }
        refreshBottomStyle(articleItem, 1)
        fontShare!!.init(articleItem, catalogItem, object : OnShareClickListener {
            override fun onSharePraiseClick() {}
            override fun onShareCommentClick() {}
            override fun onShareCollectionClick() {}
            override fun onTextFontClick() {
                if (fontResizeDialog == null) {
                    fontResizeDialog =
                        FontResizeDialog(
                            this@MicroDynamicDetailActivity,
                            this@MicroDynamicDetailActivity
                        )
                }
                fontResizeDialog?.show()
            }
        })
        //关注信息
        if (articleItem.spider_user != null) {
            topLayout.visibility = View.VISIBLE
            if(articleItem.publishdate != null){
                tvDate.text = TimeUtils.originalTimeToEndDay(articleItem.publishdate)
            }else{
                tvDate.text = articleItem.publishdate_format
            }
            authorIcon.load(articleItem.spider_user.userImage)
            tvAuthorName.text = articleItem.spider_user.userNickName
            tvAttention.visibility = View.VISIBLE
            val attention: Boolean = articleItem.isFollowed
            tvAttention.isSelected = attention
            if (attention) {
                tvAttention.text = "已关注"
            } else {
                tvAttention.text = "+ 关注"
            }
            topLayout.setOnClickListener { v: View ->
                if (isFastClick()) {
                    val intent = Intent(this, MediaAuthorDetailActivity::class.java)
                    intent.putExtra("author_id", articleItem.spiderId)
                    v.context.startActivity(intent)
                }

            }
            tvAttention.setOnClickListener { v: View ->
                v.isClickable = false
                FollowKit.followOrNot(null,
                    v.context,
                    articleItem.spiderId,
                    articleItem.spider_user.userNickName,
                    object : IAttentionCall {
                        override fun onAttentionResult(attention: Boolean) {
                            v.isClickable = true
                            if (attention) {
                                tvAttention.text = "已关注"
                            } else {
                                tvAttention.text = "+ 关注"
                            }
                        }

                        override fun onAttentionFail() {
                            v.isClickable = true
                        }
                    },
                    articleItem,
                    tvAttention
                )
            }
        } else {
            topLayout.visibility = View.GONE
        }
        //内容
        tvContent.text = articleItem.content
        //视频
        if (articleItem.prop1 == "3") {

            try {
                tvNewsTip.text = articleItem.prop4
                isAutoPlay = MMKV.defaultMMKV().decodeBool(XKey.AUTO_PLAY, false)

                val replayObj = XVideoItem(articleItem?.title)
                val video = JSONObject(articleItem.video)
                val tsAddress = VideoAddressGet.getAddress(video)
                if (tsAddress != null) {
                    for (i in 0 until tsAddress.length()) {
                        val line = tsAddress.optJSONObject(i)
                        val lineItem = XVideoBitRate()
                        lineItem.path = line.optString("url")
                        lineItem.title = line.optString("title")
                        playerV.setUrl(lineItem.path)
                        replayObj.bitRates.add(lineItem)
                    }
                }


                val jsonObject = JSONObject(articleItem.video)
                val video_info = jsonObject.optJSONObject("video_info")
                guideImg.loadX(jsonObject.optString("poster"), 3, 1, false, null)

                var width = 0
                var height = 0
                try {
                     width = video_info.optInt("width")
                     height = video_info.optInt("height")
                }catch (e:Exception){
                    e.printStackTrace()
                }

                videoContainer.visibility = View.VISIBLE
                playerV.setScreenScaleType(VideoView.SCREEN_SCALE_CENTER_CROP)
                playerV.setLooping(true)

                ivVideo.setOnClickListener {
                    posterLayout.visibility = View.GONE
                    playerV.start()
                }
                guideImg.setOnClickListener {
                    if (isFastClick()) {
                        val articles = ArrayList<ArticleItem>()
                        articles.add(articleItem)
                        TikTokActivity.startActivity(
                            tvContent.context,
                            articles,
                            0,
                            "",
                            0,
                            0,
                            false
                        )
                    }
                }
                playerV.setOnClickListener {
                    if (isFastClick()) {
                        val articles = ArrayList<ArticleItem>()
                        articles.add(articleItem)
                        TikTokActivity.startActivity(
                            tvContent.context,
                            articles,
                            0,
                            "",
                            0,
                            0,
                            false
                        )
                    }
                }
                //http://devops.res.junhaocloud.cn/project/129/issue#type=Bug&statusId=28+30+32&priorityId=94+95+96+97&pageSize=15&assignedToIds=73255&openTaskId=21063
                //按照测试说的改，不要裁剪
                if(width != 0 && height != 0){
                    val lp = playerV.layoutParams as ConstraintLayout.LayoutParams
                    lp.dimensionRatio = "W,${height}:${width}"
                    playerV.layoutParams = lp
                }else{
                if (width <= height) {
                    val lp = playerV.layoutParams as ConstraintLayout.LayoutParams
                    lp.dimensionRatio = "W,6:5"
                    playerV.layoutParams = lp
                }
                }
                playerV.postDelayed({
                    playerV.getLocalVisibleRect(rect)
                    if (rect.top == 0 && rect.bottom - rect.top >= playerV.measuredHeight * 1 / 2) {
                        if (isAutoPlay) {
                            posterLayout.visibility = View.GONE
                            playerV.start()
                        } else {
                            posterLayout.visibility = View.VISIBLE
                        }
                    }
                }, 200)
            } catch (e: JSONException) {
                e.printStackTrace()
            }

            //图片
        } else if (articleItem.prop1 == "2") {
            try {
                val image = JSONArray(articleItem.image)
                val imageData = arrayListOf<ImgData>()
                for (i in 0 until image.length()) {
                    val jsonObject = image.optJSONObject(i)
                    val src = jsonObject.optString("src")
                    val height = jsonObject.optInt("height")
                    val width = jsonObject.optInt("width")
                    val imgData = ImgData()
                    imgData.imgUrl = src
                    imgData.height = height
                    imgData.width = width
                    imageData.add(imgData)
                }
                val layoutParams = imageRv.getLayoutParams() as FrameLayout.LayoutParams

                if (imageData.size == 0) {
                    imageRv.setVisibility(View.GONE)
                } else {
                    if (imageData.size == 2 || imageData.size == 4) {
                        imageRv.setVisibility(View.VISIBLE)
                        layoutParams.width = SmartUtil.dp2px(230f)
                        imageRv.layoutParams = layoutParams
                        imageRv.layoutManager =
                            GridLayoutManager(this, 2)
                    } else {
                        imageRv.setVisibility(View.VISIBLE)
                        val spanCount = if (imageData.size == 1) 1
                        else 3
                        imageRv.addItemDecoration(
                            GridSpacingItemDecoration(
                                spanCount,
                                resources.getDimension(R.dimen.dimen3).toInt(),
                                false
                            )
                        )
                        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
                        imageRv.layoutParams = layoutParams
                        imageRv.layoutManager = GridLayoutManager(this, spanCount)
                    }
                    val gridAdapter = GridAdapter(R.layout.item_media_microimage)
                    imageRv.adapter = gridAdapter
                    gridAdapter.setNewData(imageData)
                    gridAdapter.setOnItemClickListener { adapter: BaseQuickAdapter<*, *>?, view: View, position: Int ->
                        if (isFastClick()) {
                            val intent = Intent(
                                view.context,
                                GroupPhotoNewsDetailActivity::class.java
                            )
                            articleItem.localShareType = -1
                            articleItem.isLocalSpinder = false
                            intent.putExtra("index", position)
                            intent.putExtra("data", articleItem)
                            intent.putExtra("isImgNewsJump", true)
                            view.context.startActivity(intent)
                        }

                    }
                }
            } catch (e: Exception) {
                imageRv.setVisibility(View.GONE)
            }

        }
        //底部评论
        tvCommentCount.text = "评论"
        tvLikeCount.text = "${StringUtils.toTenThousand(articleItem.supportCount)}点赞"
        mRefreshLayout.setEnableRefresh(false)
        mRefreshLayout.setOnLoadMoreListener {
            page++
            getNewsComment()
        }
        commentRv.layoutManager = LinearLayoutManager(this)
        adapter = CommentAdapter(this)
        adapter?.articleId = "${articleItem?.id}"
        adapter?.articleItem = articleItem
        commentRv.adapter = adapter
        adapter?.commentReplyListener = this
        commentListCallBack = CommentListCallBack()
        commentListInvoker = CommentListDataInvoker(commentListCallBack)
        getNewsComment()
        scrollview.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
            if (videoContainer.visibility == View.VISIBLE) {
                playerV.getLocalVisibleRect(rect)
                if (isAutoPlay) {
                    if(TXReportManager.getVisibility(playerV)){
                        posterLayout.visibility = View.GONE
                        playerV.start()
                    }else{
                        playerV.pause()
                    }
//                    if (rect.top == 0 && rect.bottom - rect.top >= playerV.measuredHeight * 1 / 2) {
//                        posterLayout.visibility = View.GONE
//                        playerV.start()
//                    } else {
//                        playerV.pause()
//                    }
                } else {
                    if(TXReportManager.getVisibility(playerV)){
                        if (!playerV.isPlaying) playerV.resume()
                    }else{
                        if (playerV.isPlaying) playerV.pause()
                    }

//                    if (rect.top == 0 && rect.bottom - rect.top >= playerV.measuredHeight * 1 / 2) {
//                        if (!playerV.isPlaying) playerV.resume()
//                    } else {
//                        if (playerV.isPlaying) playerV.pause()
//                    }
                }

            }
        }
    }

    private fun getNewsDetail() {
        newsDetailInvoker = NewsDetailInvoker(object : DataInvokeCallBack<ArticleItemReciver> {
            override fun success(data: ArticleItemReciver?) {
                data?.let {
                    if (it.state) {
                        if (data?.articleItem != null) {
                            mTyReportStartTime = System.currentTimeMillis()
                            mTyReportEndTime = mTyReportStartTime
                        }
                        articleItem = it.articleItem
                        initView()
                    } else {
                        initView()
                    }
                }
            }

            override fun fault(data: Any?) {
                initView()
            }
        })
        newsDetailInvoker!!.getArticleById(
            "" + articleItem?.getId(),
            navigate_id
        )
    }

    private fun getNewsComment() {
        if (UserInfo.isLogin(this)) {
            val userInfo = UserInfo.getUserInfo(this)
            commentListInvoker?.getCommentList(
                1,
                articleItem?.getId().toString(),
                page,
                userInfo.userid
            )
        } else {
            commentListInvoker?.getCommentList(1, articleItem?.getId().toString(), page, "")
        }
    }


    var article_id: String? = null
    var navigate_id: String? = null
    private fun setData() {
        val uriData = intent.data
        if (uriData != null) {
            isFromH5OpenToReStart = isFromH5OpenToReStart(this, uriData)
            val articleid = uriData.getQueryParameter("articleid")
            val title = uriData.getQueryParameter("title")
            val cname = uriData.getQueryParameter("cname")
            val tag = uriData.getQueryParameter("tag")
            catalogItem = CatalogItem()
            catalogItem.catname = cname
            articleItem = ArticleItem()
            try {
                articleItem.title = title
                if (!TextUtils.isEmpty(articleid)) articleItem.id = articleid!!.toLong()
            } catch (e: Exception) {
            }
        } else {
            article_id = intent.getStringExtra("article_id")
            navigate_id = intent.getStringExtra("navigate_id")
            catalogItem = intent.getParcelableExtra("catalog")
            articleItem = intent.getParcelableExtra("data")
        }
        if (catalogItem == null) catalogItem = CatalogItem()
        catalogItem.catalog_type = intent.getStringExtra("category")
        if (!TextUtils.isEmpty(navigate_id)) {
            catalogItem.catid = navigate_id
        }
        if (articleItem == null) {
            articleItem = ArticleItem()
            articleItem.id = java.lang.Long.valueOf("" + article_id)
            articleItem.summary = intent.getStringExtra("summary")
            articleItem.title = intent.getStringExtra("title")
            articleItem.url = intent.getStringExtra("url")
            articleItem.isAdvertisement = intent.getIntExtra("isAdvertisement", 0)
            articleItem.isBarrage = intent.getIntExtra("isBarrage", 0)
            articleItem.referSourceID = intent.getStringExtra("ReferSourceID")
            articleItem.isComment = intent.getStringExtra("isComment")
        }
    }

    var fontResizeDialog: FontResizeDialog? = null
    var fontShare: ShareWrap? = null

    override fun toggleTitleBar(open: Boolean) {
        super.toggleTitleBar(open)
        fontShare = ShareWrap(this, false)
        fontShare?.setShowFunction(true)
        textSizeCtl.setImageResource(R.drawable.imagetext_more)

        if (open) {
            textSizeCtl.visibility = View.VISIBLE
            textSizeCtl.setOnClickListener {
                fontShare?.show(it)
            }
        } else {
            textSizeCtl.visibility = View.GONE
        }
    }

    override fun openTitleBarSetting(): Boolean {
        return true
    }

    var lastLevel = -1

    override fun onFontChange(levelIndex: Int) {
        if (levelIndex == lastLevel) {
            return
        }
        lastLevel = levelIndex
        val zoom = AppConfig.zoomSize[levelIndex]!!
        resizeFont(levelIndex, zoom)
    }

    private fun resizeFont(levelIndex: Int, zoom: Int) {
        MMKV.defaultMMKV().putInt(XKey.MICRO_FONT_SIZE, levelIndex)
        val textSize: Float = resources.getDimension(R.dimen.dimen18) * (zoom / 100f)
        tvContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
    }

    inner class CommentListCallBack : DataInvokeCallBack<CommentListDataReciver> {

        private fun buildListDate(commentList: MutableList<NewsCommentItem>?): MutableList<Any>? {
            commentList?.let {
                val listDate: MutableList<Any> = ArrayList()
                commentList.forEach { comment ->
                    //评论
                    listDate.add(comment)
                    comment.replays?.let { replays ->
                        if (replays.size > 0) {
                            val size = min(replays.size, 2)
                            for (i in 0 until size) {
                                //评论回复
                                val reply = replays[i]
                                reply.parentCid = comment.commentid
                                reply.mainComment = comment.content
                                listDate.add(reply)
                            }
                            //查看更多的mode
                            val moreItem = MoreReplyItem(replays.size, comment)
                            listDate.add(moreItem)
                        }
                    }
                }
                return listDate
            }
            return null
        }

        override fun success(data: CommentListDataReciver) {
            mRefreshLayout?.finishLoadMore()
            mRefreshLayout?.setEnableLoadMore(data.more)
            if (data.state && data.commentList != null) {
                buildListDate(data.commentList)?.let {
                    if (it.size > 0) {
                        adapter?.dataList?.addAll(it)
                    }
                }
//                if (adapter?.dataList?.isNotEmpty()==true){
//                    mEmptyContent?.visibility=View.GONE
//                }else{
//                    mEmptyContent?.visibility=View.VISIBLE
//                }
                adapter?.notifyDataSetChanged()
                tvCommentCount.text = "评论  ${
                    StringUtils.toTenThousand(data.commentList.size.toLong())
                }"
            } else {
                fault(null)
            }
        }

        override fun fault(data: Any?) {
            page--
            mEmptyContent?.visibility=View.GONE
            mRefreshLayout?.finishLoadMore()
            mRefreshLayout?.setEnableLoadMore(false)
        }


    }

    class GridAdapter(layoutResId: Int) : BaseQuickAdapter<ImgData, BaseViewHolder>(layoutResId) {
        private val options = RequestOptions()
            .error(AppFactoryGlobalConfig.getDefaultImageLoadDrawable())
            .fallback(AppFactoryGlobalConfig.getDefaultImageLoadDrawable())

        override fun convert(helper: BaseViewHolder, item: ImgData) {
            val view = helper.getView<ImageView>(R.id.image)
            val layoutParams = view.layoutParams as ConstraintLayout.LayoutParams
            layoutParams.width = matchParent
            if (itemCount == 1) {
                Glide.with(view.context)
                    .setDefaultRequestOptions(options)
                    .asBitmap()
                    .load(item.imgUrl)
                    .into(object : SimpleTarget<Bitmap?>() {
                        override fun onLoadFailed(errorDrawable: Drawable?) {
                            view.setImageDrawable(errorDrawable)
                        }

                        override fun onResourceReady(
                            resource: Bitmap,
                            transition: Transition<in Bitmap?>?
                        ) {
                            val currentWidth =
                                DisplayUtils.getScreenWidth(view.context) - DisplayUtils.dp2px(
                                    view.context,
                                    30f
                                )
                            var currentHeight = 0
                            if (resource.width > 0 && resource.height > 0) {
                                view.scaleType = ImageView.ScaleType.FIT_CENTER
                            }
                            val layoutParam = view.getLayoutParams()
                            if (layoutParam != null) {
                                layoutParam.width = currentWidth
                                layoutParam.height = wrapContent
                                view.layoutParams = layoutParam
                            }

                            view.setImageBitmap(resource)
                        }
                    })
            } else {

                layoutParams.width = matchParent
                view.scaleType = ImageView.ScaleType.CENTER_CROP
                layoutParams.height = view.context.resources.getDimension(R.dimen.dimen112).toInt()
                view.layoutParams = layoutParams
                view.load(item.imgUrl)
            }
        }


    }


    override fun onResume() {
        super.onResume()
        playerV.resume()
        tvAttention.isSelected = FollowKit.isFollowed(articleItem.spiderId)
        if (tvAttention.isSelected) {
            tvAttention.text = "已关注"
        } else {
            tvAttention.text = "+ 关注"
        }
    }

    override fun onPause() {
        super.onPause()
        playerV.pause()
    }

    override fun finish() {
        super.finish()
        if (articleItem != null && mTyReportStartTime > 0) {
            mTyReportEndTime = System.currentTimeMillis()
        }
        playerV.release()

    }


    override fun onCommentReply(item: NewsCommentItem?) {
        if (UserInfo.isLogin(this)) {
//            commentPop.isReply = true
//            commentPop.setReplyData(item)
//            commentPop.access_token = UserInfo.getUserInfo(this).access_token
//            commentPop.setAnonymousView()
//            commentPop.show(mRootView)

            CommentDialog.startActivity(
                this@MicroDynamicDetailActivity,
                articleItem,
                1,
                UserInfo.getUserInfo(this).access_token,
                false,
                true,
                item!!
            )

        } else {
            LoginUtils.request_source=LoginUtils.source_comment;
            LoginUtils.invokeLogin(this)
        }
    }

    override fun onCommentReply(item: ReplyCommentItem?) {

    }


    override fun onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        super.onDestroy()
    }
}